/**
 * @(#)com.tansun.easycare.rule.excel.service.RuleDatasetExcelService.java Copyright (c) 2017
 * 天阳宏业科技股份有限公司
 */
package com.tansun.easycare.rule.excel.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tansun.easycare.core.utils.IdGen;
import com.tansun.easycare.rule.common.service.DataBomService;
import com.tansun.easycare.rule.datamodel.dao.RuleDataDomainDao;
import com.tansun.easycare.rule.datamodel.dao.RuleDataparamsDao;
import com.tansun.easycare.rule.datamodel.dao.RuleDatasetDao;
import com.tansun.easycare.rule.datamodel.entity.RuleDataDomain;
import com.tansun.easycare.rule.datamodel.entity.RuleDataparams;
import com.tansun.easycare.rule.datamodel.entity.RuleDataset;
import com.tansun.easycare.rule.datamodel.service.RuleDataparamsService;
import com.tansun.easycare.rule.excel.entity.ruledataset.RuleDataParamsExcelEntity;
import com.tansun.easycare.rule.excel.entity.ruledataset.RuleDatasetExcelEntity;
import com.tansun.easycare.rule.excel.service.RuleDatasetExcelService;
import com.tansun.easycare.rule.excel.utils.BeanUtil;
import com.tansun.easycare.rule.excel.utils.ExcelErrorMsg;
import com.tansun.easycare.rule.excel.utils.ExcelUitl;
import com.tansun.easycare.rule.utils.ExcelConstant;

/**
 *
 * @author zengdong
 * @version 1.0  2017年5月22日
 * @modified zengdong  2017年5月22日  <创建>
 */
@Service
public class RuleDatasetExcelServiceImpl implements RuleDatasetExcelService {

//	@Autowired
//	private DataModelServiceImpl dataModelService;
	
	@Autowired
	private DataBomService dataBomService;
	
	@Autowired
	private RuleDataparamsService ruleDataparamsService;

    @Autowired
    private RuleDataDomainDao ruleDataDomainDao;

    @Autowired
    private RuleDatasetDao ruleDatasetDao;

    @Autowired
    private RuleDataparamsDao ruleDataparamsDao;

    /**
     * 获取数据集
     * @param projectCode
     * @param id
     * @return
     */
    public List<RuleDatasetExcelEntity> getRuleDatasetList(String projectCode, String id) {
        if (StringUtils.isNotBlank(projectCode)) {
            RuleDataset set = new RuleDataset();
            set.setProjectcode(projectCode);
            //若有制定数据集则需要绑定对应参数
            if (StringUtils.isNotBlank(id)) {
                set.setId(id);
            }
            List<RuleDataset> ruleDatasetList = ruleDatasetDao.getList(set);
            List<RuleDatasetExcelEntity> ruleDatasetExcelEntityList = new ArrayList<RuleDatasetExcelEntity>();
            if (ruleDatasetList != null && ruleDatasetList.size() > 0) {
            	//获取缓存
            	Map<String,List<RuleDataparams>> map2RDP = ruleDataparamsService.findParamsKeyDsetIdByProjectCode(projectCode);
            	Map<String, List<RuleDataDomain>> domainMap = dataBomService.findDomainMap();
            	for (RuleDataset dataset : ruleDatasetList) {
                    RuleDatasetExcelEntity entity = new RuleDatasetExcelEntity();
                    BeanUtil.copyProperties(dataset, entity);
                    List<RuleDataparams> ruleDataparamsList = map2RDP.get(dataset.getId());
                    List<RuleDataParamsExcelEntity> ruleDataParamsExcelEntityList = new ArrayList<RuleDataParamsExcelEntity>();
                    if (ruleDataparamsList != null && ruleDataparamsList.size() > 0) {
                        for (RuleDataparams dataparams : ruleDataparamsList) {
                            RuleDataParamsExcelEntity paramsEntity = new RuleDataParamsExcelEntity();
                            BeanUtil.copyProperties(dataparams, paramsEntity);
                            //构建参数
                            if (StringUtils.isNotBlank(dataparams.getId())) {
                                //获取离散类型数据
                                List<RuleDataDomain> domainList = domainMap.get(dataparams.getId());
                                if (domainList != null && domainList.size() > 0) {
                                    paramsEntity.setRuledomainList(domainList);
                                }
                            }
                            ruleDataParamsExcelEntityList.add(paramsEntity);
                        }
                        entity.setParamsList(ruleDataParamsExcelEntityList);
                    }
                    ruleDatasetExcelEntityList.add(entity);
                }
            }
            return ruleDatasetExcelEntityList;
        }
        return null;
    }

    /**
     * 数据校验
     * @param map
     * @return
     */
    public ExcelErrorMsg verifyRuleDataset(List<RuleDatasetExcelEntity> ruleDatasetList, String projectCode) {
        //新建错误信息
        ExcelErrorMsg msg = new ExcelErrorMsg();
        if (ruleDatasetList != null && ruleDatasetList.size() > 0) {
            //校验数据集
            int datasetNum = 1;
            for (RuleDatasetExcelEntity dataset : ruleDatasetList) {
                //从第2行开始计算
                datasetNum++;

                //校验name
                if (StringUtils.isEmpty(dataset.getName())) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISNULL_ERRORMSG, datasetNum + "", "name"));
                } else if (dataset.getName().length() > 50) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_OVER_LENGTH, datasetNum + "", "name", "50"));
                }

                //校验paramType
                if (StringUtils.isEmpty(dataset.getParamType())) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISNULL_ERRORMSG, datasetNum + "", "paramType"));
                } else if (dataset.getParamType().length() > 10) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_OVER_LENGTH, datasetNum + "", "type", "10"));
                } else {
                    //校验类型
                    if (ExcelConstant.CLASS_PARAMS_TYPE.contains(dataset.getParamType().toUpperCase())) {
                        //类型匹配，转大写保存
                        dataset.setParamType(dataset.getParamType().toUpperCase());
                    } else {
                        //不匹配，抛异常
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_PARAMTYPE_ERRORMSG, datasetNum + "", "paramType"));
                    }
                }

                //校验chzn
                if (StringUtils.isEmpty(dataset.getChzn())) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISNULL_ERRORMSG, datasetNum + "", "chzn"));
                } else if (dataset.getChzn().length() > 50) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_OVER_LENGTH, datasetNum + "", "chzn", "50"));
                }

                //校验desc
                if (StringUtils.isNotBlank(dataset.getDataDesc()) && dataset.getDataDesc().length() > 100) {
                    msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_OVER_LENGTH, datasetNum + "", "desc", "100"));
                }

                //校验重复问题
//				if(StringUtils.isNotBlank(dataset.getName()) && StringUtils.isNotBlank(dataset.getChzn())){
//					//1、比较数据库已有的数据
//					RuleDataset  queryData = new RuleDataset();
//					queryData.setProjectcode(projectCode);
//					List<RuleDataset> datasetList = ruleDatasetDao.findList(queryData);
//					if(datasetList != null && datasetList.size() > 0){
//						for(RuleDataset set : datasetList){
//							if(StringUtils.isNotBlank(set.getName()) && set.getName().equals(dataset.getName())){
//								msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISEXISTS_INDB_ERRORMSG,datasetNum + "","name"));										
//							}
//							if(StringUtils.isNotBlank(set.getChzn()) && set.getChzn().equals(dataset.getChzn())){
//								msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISEXISTS_INDB_ERRORMSG,datasetNum + "","chzn"));										
//							}
//						}
//					}
//					//2、比较Excel中已有的数据
//					int index = 1;
//					for(RuleDatasetExcelEntity set : ruleDatasetList){
//						index++ ;
//						if(set.getName().equals(dataset.getName()) && index != datasetNum){
//							msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISEXISTS_INEXCEL_ERRORMSG,datasetNum + "","name"));										
//						}
//						if(set.getChzn().equals(dataset.getChzn()) && index != datasetNum){
//							msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.CLASS_ISEXISTS_INEXCEL_ERRORMSG,datasetNum + "","chzn"));										
//						}
//					}
//				}
                //给数据集赋ID
                //if(StringUtils.isEmpty(dataset.getId())){
                dataset.setId(IdGen.uuid());
                //}
            }

            //校验数据集变量
            List<RuleDataParamsExcelEntity> ruleDataparams = ruleDatasetList.get(0).getParamsList();
            if (ruleDataparams != null && ruleDataparams.size() > 0) {
                int dataParamNum = 1;
                for (RuleDataparams dataParams : ruleDataparams) {
                    //从第2行开始计算
                    dataParamNum++;

                    dataParams.setId(IdGen.uuid());

                    //校验class
                    if (StringUtils.isEmpty(dataParams.getDatasetId())) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISNULL_ERRORMSG, dataParamNum + "", "class"));
                    } else if (StringUtils.isNotBlank(dataParams.getDatasetId()) && dataParams.getDatasetId().length() > 50) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "class", "50"));
                    } else if (StringUtils.isNoneBlank(dataParams.getDatasetId())) {
                        //比较是否在class中是否有定义
                        List<RuleDatasetExcelEntity> setList = ruleDatasetList;
                        int i;
                        int m = 0;
                        for (i = 0; i < setList.size(); i++) {
                            RuleDataset set = setList.get(i);
                            if (set.getName().equals(dataParams.getDatasetId())) {
                                dataParams.setDatasetId(set.getId());
                                m++;
                                break;
                            }
                        }
                        if (m == 0) {
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_CLASS_ISNOTEXISTS, dataParamNum + ""));
                        }
                    }

                    //校验name
                    if (StringUtils.isEmpty(dataParams.getName())) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISNULL_ERRORMSG, dataParamNum + "", "name"));
                    } else if (StringUtils.isNotBlank(dataParams.getName()) && dataParams.getName().length() > 50) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "name", "50"));
                    }

                    //校验chzn
                    if (StringUtils.isEmpty(dataParams.getChzn())) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISNULL_ERRORMSG, dataParamNum + "", "chzn"));
                    } else if (StringUtils.isNotBlank(dataParams.getChzn()) && dataParams.getChzn().length() > 50) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "chzn", "50"));
                    }

                    //校验name和chzn是否有重复
                    if (StringUtils.isNotBlank(dataParams.getName()) && StringUtils.isNotBlank(dataParams.getChzn())) {
                        List<RuleDataParamsExcelEntity> ruleDataparamsList = ruleDatasetList.get(0).getParamsList();
                        int index = 1;
                        for (RuleDataparams params : ruleDataparamsList) {
                            index++;
//							if(params.getName().equals(dataParams.getName()) && index != dataParamNum){
//								msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISEXISTS_INEXCEL_ERRORMSG,dataParamNum + "","name"));										
//							}
                            if (params.getChzn().equals(dataParams.getChzn()) && index != dataParamNum) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISEXISTS_INEXCEL_ERRORMSG, dataParamNum + "", "chzn"));
                            }
                        }
                    }

                    //校验type
                    if (StringUtils.isEmpty(dataParams.getType())) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISNULL_ERRORMSG, dataParamNum + "", "type"));
                    } else if (StringUtils.isNotBlank(dataParams.getType()) && dataParams.getType().length() > 10) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "type", "10"));
                    } else if (StringUtils.isNotBlank(dataParams.getType())) {
                        //校验类型
                        if (ExcelConstant.FIELD_PARAMS_TYPE.contains(dataParams.getType().toUpperCase())) {
                            //类型匹配，转首字母大写
                            dataParams.setType(ExcelUitl.conversionStr(dataParams.getType()));
                        } else {
                            //不匹配，抛异常
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_PARAMTYPE_ERRORMSG, dataParamNum + "", "type"));
                        }
                    }

                    //校验desc
                    if (StringUtils.isNotBlank(dataParams.getParamDesc()) && dataParams.getParamDesc().length() > 200) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "desc", "200"));
                    }

                    //校验domain
                    if (StringUtils.isNotBlank(dataParams.getDomain()) && dataParams.getDomain().length() > 45) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "domain", "45"));
                    } else {
                        // 判断枚举类型的domain是否和id一致
                        if (StringUtils.isNotBlank(dataParams.getDomain()) && !dataParams.getDomain().startsWith("[")) {
                            if (!dataParams.getDomain().equals(dataParams.getId())) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_DOMAIN_NOTEQUAL_ID, dataParamNum + ""));
                            }
                        }
                    }

                    //校验domainStr
                    if (StringUtils.isNotBlank(dataParams.getDomainStr()) && dataParams.getDomainStr().length() > 1000) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "domainStr", "1000"));
                    }

                    //校验collection
                    if (StringUtils.isNotBlank(dataParams.getCollection()) && dataParams.getCollection().length() > 50) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "collection", "50"));
                    }

                    //校验isout
                    if (StringUtils.isNotBlank(dataParams.getIsout()) && dataParams.getIsout().length() > 10) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "collection", "50"));
                    } else if (StringUtils.isNotBlank(dataParams.getIsout())) {
                        //校验类型
                        if (ExcelConstant.FIELD_TF_TYPE.contains(dataParams.getIsout().toLowerCase())) {
                            //类型匹配，转小写
                            dataParams.setIsout(dataParams.getIsout().toLowerCase());
                        } else {
                            //不匹配，抛异常
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_TF_ERRORMSG, dataParamNum + "", "isout"));
                        }
                    }

                    //校验pattern
                    if (StringUtils.isNotBlank(dataParams.getPattern()) && dataParams.getPattern().length() > 20) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "pattern", "20"));
                    }

                    //校验mathStr
                    if (StringUtils.isNotBlank(dataParams.getMathStr()) && dataParams.getMathStr().length() > 200) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "mathStr", "200"));
                    }

                    //校验defaultValue
                    if (StringUtils.isNotBlank(dataParams.getDefaultValue()) && dataParams.getDefaultValue().length() > 50) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "defaultValue", "50"));
                    }

                    //校验isDeriver
                    if (StringUtils.isNotBlank(dataParams.getIsDerives()) && dataParams.getIsDerives().length() > 10) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "isDerives", "10"));
                    } else if (StringUtils.isNotBlank(dataParams.getIsDerives())) {
                        //校验类型
                        if (ExcelConstant.FIELD_TF_TYPE.contains(dataParams.getIsDerives().toLowerCase())) {
                            //类型匹配，转小写
                            dataParams.setIsDerives(dataParams.getIsDerives().toLowerCase());
                        } else {
                            //不匹配，抛异常
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_TF_ERRORMSG, dataParamNum + "", "isDerives"));
                        }
                    }

                    //校验isCollection
                    if (StringUtils.isNotBlank(dataParams.getIsCollections()) && dataParams.getIsCollections().length() > 10) {
                        msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_OVER_LENGTH, dataParamNum + "", "isCollections", "10"));
                    } else if (StringUtils.isNotBlank(dataParams.getIsCollections())) {
                        //校验类型
                        if (ExcelConstant.FIELD_TF_TYPE.contains(dataParams.getIsCollections().toLowerCase())) {
                            //类型匹配，转小写
                            dataParams.setIsCollections(dataParams.getIsCollections().toLowerCase());
                        } else {
                            //不匹配，抛异常
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_TF_ERRORMSG, dataParamNum + "", "isCollections"));
                        }
                    }
                }

                //校验离散型变量
                List<RuleDataDomain> ruleDataDomain = ruleDataparams.get(0).getRuledomainList();
                if (ruleDataDomain != null && ruleDataDomain.size() > 0) {
                    int dataDomainNum = 1;
                    for (RuleDataDomain dataDomain : ruleDataDomain) {
                        //从第2行开始计算
                        dataDomainNum++;

                        dataDomain.setId(IdGen.uuid());

                        //校验ID
                        if (StringUtils.isNotEmpty(dataDomain.getId())) {
                            if (dataDomain.getId().length() > 64) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_OVER_LENGTH, dataDomainNum + "", "id", "64"));
                            }
                            if (!dataDomain.getId().matches(".*\\p{Alpha}.*")) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_IDCONTAIN_LETTER, dataDomainNum + ""));
                            }
                        }

                        //校验DOMAIN
                        if (StringUtils.isNotEmpty(dataDomain.getDomainId())) {
                            if (dataDomain.getDomainId().length() > 64) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_OVER_LENGTH, dataDomainNum + "", "domainId", "64"));
                            }
                            if (!dataDomain.getDomainId().matches(".*\\p{Alpha}.*")) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_DOMAINIDCONTAIN_LETTER, dataDomainNum + ""));
                            }

                            //判断domain是否有对应值
                            List<RuleDataParamsExcelEntity> ruleDataparamsList = ruleDataparams;
                            int i = 0;
                            for (i = 0; i < ruleDataparamsList.size(); i++) {
                                RuleDataparams params = ruleDataparamsList.get(i);
                                if (params.getDomain().equals(dataDomain.getDomainId())) {
                                    break;
                                }
                            }
                            if (i == ruleDataparamsList.size()) {
                                msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_DOMAIN_NOTIN_PARAMS, dataDomainNum + "" + dataDomain.getDomainId()));
                            }
                        }

                        //校验name
                        if (StringUtils.isEmpty(dataDomain.getName())) {
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_ISNULL_ERRORMSG, dataDomainNum + "", "name"));
                        } else if (StringUtils.isNotBlank(dataDomain.getName()) && dataDomain.getName().length() > 200) {
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_OVER_LENGTH, dataDomainNum + "", "name", "200"));
                        } else {
//							List<RuleDataDomain> ruleDataDomainList = ruleDataparams.get(0).getRuledomainList();
//							int index = 1;
//							for(RuleDataDomain domain : ruleDataDomainList){
//								index++ ;
//								if(domain.getName().equals(dataDomain.getName()) && index != dataDomainNum){
//									//msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.FIELD_ISEXISTS_INEXCEL_ERRORMSG,dataDomainNum + "","name"));										
//								}
//							}
                        }

                        //校验domain_value
                        if (StringUtils.isEmpty(dataDomain.getDomainValue())) {
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_ISNULL_ERRORMSG, dataDomainNum + "", "domain_value"));
                        } else if (StringUtils.isNotBlank(dataDomain.getDomainValue()) && dataDomain.getDomainValue().length() > 100) {
                            msg.addErrorMsg(ExcelConstant.getErrorMsgConstant(ExcelConstant.DOMAIN_OVER_LENGTH, dataDomainNum + "", "name", "100"));
                        }
                    }
                }
            }
        }
        return msg;
    }

    /**
     * 保存Excel导入记录
     * @param ruleDatasetList
     */
    @Transactional
    public void saveExcelInfoToDb(List<RuleDatasetExcelEntity> ruleDatasetList) {
        if (ruleDatasetList != null && ruleDatasetList.size() > 0) {
            //保存数据集
            for (RuleDatasetExcelEntity set : ruleDatasetList) {
                if (StringUtils.isBlank(set.getId())) {
                    set.setId(IdGen.uuid());
                }
                ruleDatasetDao.insert(BeanUtil.copyProperties(set, new RuleDataset()));
            }
            //保存数据集变量
            List<RuleDataParamsExcelEntity> dataparamsList = ruleDatasetList.get(0).getParamsList();
            if (dataparamsList != null && dataparamsList.size() > 0) {
                for (RuleDataparams params : dataparamsList) {
                    ruleDataparamsDao.insert(BeanUtil.copyProperties(params, new RuleDataparams()));
                }
                //保存离散型变量
                List<RuleDataDomain> datadomainList = dataparamsList.get(0).getRuledomainList();
                if (datadomainList != null && datadomainList.size() > 0) {
                    for (RuleDataDomain domain : datadomainList) {
                        ruleDataDomainDao.insert(domain);
                    }
                }
            }
        }
    }

}
